package com.feifan.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.feifan.api.annotation.LogType;
import com.feifan.api.annotation.SystemLog;
import com.feifan.api.annotation.UserLoginToken;
import com.feifan.api.model.OmsOrderSetting;
import com.feifan.api.service.IOmsOrderSettingService;
import com.feifan.common.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * @program: FinalProject
 * @author: Xiaofan
 * @createTime: 2021-08-09 12:43
 * @description: Functions of this class is
 **/
@RestController
@CrossOrigin
@RequestMapping(value = "/orderSetting")
@Api(tags = "OmsOrderSettingController",description= "订单设置管理")
public class OmsOrderSettingController {

    //dubbo做法
    @Reference(
            version ="1.0.0",
            interfaceName = "com.feifan.api.service.IOmsOrderSettingService",
            interfaceClass = IOmsOrderSettingService.class,
            timeout = 170000
    )
    private IOmsOrderSettingService service;

    @ApiOperation(value = "获取指定订单设置")
    @ResponseBody
    @GetMapping(value = "/{id}")
    @UserLoginToken
    @SystemLog(description ="获取指定订单设置",type = LogType.ORDER_DETAIL_SETTING)
    public CommonResult<OmsOrderSetting> getItem(@PathVariable Long id){
        return CommonResult.success(service.getIntem(id));
    }

    @ApiOperation(value = "修改指定订单配置")
    @ResponseBody
    @PostMapping(value = "/update/{id}")
    @UserLoginToken
    @SystemLog(description ="修改指定订单配置",type = LogType.ORDER_UPDATE_DETAIL_SETTING)
    public CommonResult<OmsOrderSetting> update(@PathVariable Long id,@RequestBody OmsOrderSetting omsOrderSetting){
        CommonResult commonResult;
        try {
            service.update(id,omsOrderSetting);
            commonResult=CommonResult.success(true);
        }
        catch (Exception e){
            commonResult=CommonResult.failed();
            e.printStackTrace();
        }
        return commonResult;
    }
}